#include "image.h"
#include <sstream>

using namespace std;

bool Image::isGrayOrMono()
{
	if(colorRange != RGB) return true;
	else return false;
}

void Image::setVersion(string version)
{

	if(version == "P1")     { fileType = ASCII; colorRange = MONO;}
	else if(version == "P2"){ fileType = ASCII; colorRange = GRAY;}
	else if(version == "P3"){ fileType = ASCII; colorRange = RGB;}
	else if(version == "P4"){ fileType = BINARY; colorRange = MONO;}
	else if(version == "P5"){ fileType = BINARY; colorRange = GRAY;}
	else if(version == "P6"){ fileType = BINARY; colorRange = RGB;}

	if(colorRange == MONO) max_value = 1;
}

string Image::getVersion()
{
	int type = 0;
	switch(colorRange)
	{
		case MONO: type = 1; break;
		case GRAY: type = 2; break;
		case RGB: type = 3; break;
	}

	if(fileType == BINARY) type += 3;

	stringstream myString;
	myString << "P" << type;

   return myString.str();
}

int Image::getBytesPerPixel()
{
	if(colorRange == RGB) return 3;
	else return 1;
}

unsigned int Image::getSize()
{
	return width * height * getBytesPerPixel();
}

